package com.zxc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxc.dao.OrdersMapper;
import com.zxc.entity.Orders;
import com.zxc.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;

    @Override
    public List<Orders> selectOrdersByCustName(String custName) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("odr_customer",custName);
        List<Orders> ordersList = ordersMapper.selectList(queryWrapper);
        return ordersList;
    }

    @Override
    public List<Orders> selectOrdersByCustNameAndDate(String custName, String searchYear) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("odr_customer",custName);
        String searchYears = (Integer.parseInt(searchYear)+1)+"-01-01 00:00:00";
        searchYear = searchYear + "-01-01 00:00:00";
        List<Orders> ordersList = ordersMapper.selectOrdersByCustNameAndDate(custName,searchYear,searchYears);
        return ordersList;
    }
}
